<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<div class="fab">
		<form id="stepForm" action="/post/index-step-2.html" method="post">
        <input type="hidden" name="task_id" id="task_id" value="559771" />
                <input type="hidden" id="mode" name="mode" value="0"/>
        <p class="tit"><span class="gray1"><strong>您想一夜之间贴子发遍网络，还是有实际预算按量付费</strong></span></p>
        <ul class="wkxz clearfix" id="wkx">

        	<li class="mr10 sele" radioValue="0">
            	<p class="tie">发贴比赛</p>
                <p class="con">不限发贴数量，发贴最多者中标</p>
                <p class="lis mt15">·可以在极短时间内，调动大批卖家发出大量贴子
</p>
				<p class="lis">·网站智能统计，并附效果报表</p>
            </li>
        	<li class="ml10" radioValue="1">

            	<p class="tie">计件发贴</p>
                <p class="con">计件算报酬，只需向合格的贴子付钱</p>
                <p class="lis mt15">·保证信息传达精准、到位</p>
				<p class="lis">·杜绝卖家重复交稿或作弊，保障买家利益</p>
            </li>
			<input type="hidden" id="postmode" name="postmode" value="0"/>
        </ul>

        		<div id="select-caseMode">
			<div class="layout-arrow"></div>
			<p style="height:34px">
				<strong class="at_text_title">任务赏金：</strong>
				<span class="reward at_text t_1_d"><input maxlength="7" name="amount" size="14" value="" id="m-count-i"><em>元，我希望</em></span>
                <select class="select-list" name="allot" style="position:relative;top:-8px;*top:-6px">
                    <option value="0" selected="true">只选一人中标</option>

                    <option value="1">选多人中标</option>
                                    </select>
            </p>
			<div class="show-mode">

				<p class="s-cot gray2">
                	<strong>您还有<span class="m-count orange1">-</span>元的<span class="m-percentage orange1">100%</span>可分配<a class="add-member blue2" href="javascript:void(0);">增加奖项</a></strong>

            	</p>
            	                <p class="thinkgj mt10 clearfix gray3">
                	<span class="mt5">一等奖</span>
                	<span class="at_text t_1_d"><input maxlength="8" size="8" name="many_num[]" value=""></span><span class="mt5">人，平分总奖金的</span>
                	<span class="at_text t_1_d"><input maxlength="12" size="12" name="many_amount[]" value="" class="case1-money"></span><span class="mt5">%</span>
					<a href="javascript:void(0);" class="remove-member blue2">取消</a>
            	</p>

            	<p class="thinkgj mt10 clearfix gray3">
                	<span class="mt5">二等奖</span>
                	<span class="at_text t_1_d"><input maxlength="8" size="8" name="many_num[]" value=""></span><span class="mt5">人，平分总奖金的</span>
                	<span class="at_text t_1_d"><input maxlength="12" size="12" name="many_amount[]" value="" class="case1-money"></span><span class="mt5">%</span>
					<a href="javascript:void(0);" class="remove-member blue2">取消</a>
            	</p>
            	<p class="thinkgj mt10 clearfix gray3">

                	<span class="mt5">三等奖</span>
                	<span class="at_text t_1_d"><input maxlength="8" size="8" name="many_num[]" value=""></span><span class="mt5">人，平分总奖金的</span>
                	<span class="at_text t_1_d"><input maxlength="12" size="12" name="many_amount[]" value="" class="case1-money"></span><span class="mt5">%</span>
					<a href="javascript:void(0);" class="remove-member blue2">取消</a>
            	</p>
                			</div>
			<div class="show-mode">

				<p class="mt15 gray2">
                	<strong>赏金总额<span class="m-count orange1">-</span>元，您希望怎么分配赏金？</strong>
            	</p>
                <p>
                                计件发贴单价不能低于0.3元
                </p>
            	<p class="thinkgj mt10 clearfix gray3">
                	<span class="at_text t_1_d"><input maxlength="8" size="8" name="piece_num" value="" class="case2-num"></span><span class="mt5">个贴子，每个</span>

                	<span class="at_text t_1_d"><input maxlength="12" size="12" name="piece_amount" value="" class="case2-pce"></span><span class="mt5">元</span>
            	</p>
			</div>
		</div>
		        <p class="tc"><a href="/post/index-step-1-tid-559771.html">返回上一步</a><a id="submitMoney" class="at_but b_1_y" href="javascript:void(0);"><u></u>下一步</a></p>
   		</form>
    </div>
<script>
var skillSetting = { 
		countm: null,
			selectmode: "wanlger",
		unitprice:0.3
		};
(function() {
	var e_con = $("#wkx"), 
		e_box = $("#select-caseMode"), 
		e_tip = e_box.find(">.layout-arrow"),
		e_li = e_con.children("li"), 
		e_hideValue = e_con.find("input[type='hidden']");
	var sel_box = $("#select-caseMode"),
		select = sel_box.find("select.select-list"),
		method = sel_box.children(".show-mode"),
		countm = skillSetting.countm,
		m_count_i = $("#m-count-i"),
		m_count_i_em = m_count_i.next(),
		case1 = method.eq(0),
		case2 = method.eq(1),
		case1_count = case1.find(">p:eq(0) .m-count"),
		case1_percentage = case1.find(">p:eq(0) .m-percentage"),
		case2_count = case2.find(">p:eq(0) .m-count"),
		addbt = case1.find(">p:eq(0) .add-member"),
		award = case1.children("p.thinkgj"),
		piecenum = case2.find("input.case2-num"),
		piecepce = case2.find("input.case2-pce"),
		margin = $("#setting-margin"),
		submitMoney = $("#submitMoney");
	e_li.hover(
		function(){
			$(this).addClass("hove");
		},function () {
			$(this).removeClass("hove");
		}
	).click(function(){
		e_li.removeClass("sele");
		$(this).addClass("sele");
		e_hideValue.val($(this).attr("radioValue"));
		if(skillSetting.selectmode == "default") {
			if (e_hideValue.val() == "0") {
				e_tip.removeClass("arrow-r");
				select.css("visibility", "visible");
				m_count_i_em.css("visibility", "visible");
				showcase();
			} else {
				e_tip.addClass("arrow-r");
				select.css("visibility", "hidden");
				m_count_i_em.css("visibility", "hidden");
				method.hide();
			}
		} else if (skillSetting.selectmode == "wanlger") {
			method.hide();
			if (e_hideValue.val() == "0") {
				e_tip.removeClass("arrow-r");
				select.html("<option value=\"0\" selected=\"true\">只选一人中标</option><option value=\"1\">选多人中标</option>");
				select.val("0");
				showcase();
			} else {
				e_tip.addClass("arrow-r");
				select.html("<option value=\"2\">计件算酬劳,合格一个算一个</option>");
				select.val("2");
				showcase();
			}
		}
	});
		
				e_li.eq(0).click();
				function _init_(){
		if(countm == null) countm = "-";
		m_count_i.val((countm=="-")?"":countm);
		case1_count.text(countm);
		case2_count.text(countm);
		focusblur();
		showcase();
		showcancel();
		dealaward();
			}	
	_init_();
	
	select.change(function() {showcase()});
	addbt.click(function() {addaward()});
	piecenum.bind("blur",function() {dealPiece("num")});
	piecepce.bind("blur", function() {dealPiece("pce")});
	m_count_i.bind("blur", function() {change_count($(this))});
	
	function change_count(o) {
		var val = o.val();
		if (skillSetting.countm == val) return;
		if (check_count(o, val)) {
			skillSetting.countm = o.val();
			countm = skillSetting.countm;
		} else {
			countm = "";
			skillSetting.countm = countm;
			clearPiece();
		}
		case1_count.text(countm);
		clearPiece();
	}
	
	function check_count(inp, val) {
		if (val == "" || val.length == 0 || /^\s*$/ig.test(val)) {
			inp.val("");
			return false;
		}
		if (/[^0-9]/.test(val)) {
			at_infoTrace.show("请输入正确的任务赏金金额");
			inp.val("");
			return false;
		}
		var money = parseInt(val);
		if (money < 50 || money >= 10000000) {
			at_infoTrace.show("任务赏金不能小于<span class=\"orange1\">50</span>元");
			inp.val("");
			return false;
		}
		return true;
	}
	
	function focusblur() {
		inputs = sel_box.find("input[type='text']");
		inputs.unbind();
		inputs.bind("focus", function(){$(this).parent().attr("className", "at_text t_1_i")});
		inputs.bind("blur", function(){$(this).parent().attr("className", "at_text t_1_d")});
		piecenum.bind("blur",function() {dealPiece("num")});
		piecepce.bind("blur", function() {dealPiece("pce")});
		m_count_i.bind("blur", function() {change_count($(this))});
	}
	
	function showcase() {
		method.hide();
		margin.attr("disabled", false);
		switch(select.val()) {
			case "1": {
				case1.show();
			};break;
			case "2": {
				case2.show();
				margin.attr("checked", true);
				margin.attr("disabled", true);
			};break;
		}
	}
	
	function dealaward() {
		var count = case1_percentage.text().replace(/(?:\%*)|(?:^\s*)|(?:\s*$)/g,""),
			numbe = null,
			money = null,
			input = null,
			iscgn,
			iscgm;
		for(i=0; i<award.length; i++) {
			input = award.eq(i).find("input");
			numbe = input.eq(0);
			money = input.eq(1);
			iscgn = false;
			iscgm = false;
			if(numbe.val().replace(/\s*/,"") == "") iscgn = true;
			if(money.val().replace(/\s*/,"") == "") iscgm = true;
			if(i==0) {
				if(iscgn) numbe.val(1);
				if(iscgm) money.val(count * 0.7);
			} else if (i==1) {
				if(iscgn) numbe.val(2);
				if(iscgm) money.val(count * 0.2);
			} else if (i==2) {
				if(iscgn) numbe.val(3);
				if(iscgm) money.val(count * 0.1);
			} else {
				if(iscgn) numbe.val(1);
				if(iscgm) money.val(0);
			}
		}
		setCount_1();
	}

	function setCount_1() {
		bindAwardEvent();
		var input = case1.find("input.case1-money"),
			count = 0;
		for(var i=0; i<input.length; i++) {
			if(!/^[0-9\.]+$/.test(input.eq(i).val())) continue;
			count += Number(input.eq(i).val());
		}
		if (count < 0 || count > 100) return false;
		else {
			case1_percentage.text((100-count)+"%");
			return true;
		}
	}

	function addaward() {
		var count = award.length;
		if (count + 1 > 10) {
			at_infoTrace.show("最多只能有10个奖项", "i");
			return;
		}
		var newitem = "<p class=\"thinkgj mt10 clearfix gray3\"><span class=\"mt5\">"+getChinese(count+1)+"等奖</span><span class=\"at_text t_1_d\"><input maxlength=\"8\" size=\"8\" value=\"1\" name=\"many_num[]\"></span><span class=\"mt5\">人，平分总奖金的</span><span class=\"at_text t_1_d\"><input name=\"many_amount[]\" maxlength=\"12\" size=\"12\" value=\"0\" class=\"case1-money\"></span><span class=\"mt5\">%</span><a href=\"####\" class=\"remove-member blue2\">取消</a></p>";
		case1.append(newitem);
		award = case1.children("p.thinkgj");
		showcancel();
		setCount_1();
	}

	function showcancel() {
		award = case1.children("p.thinkgj");
		var oldCancel = award.children(".remove-member"),
			newCancel = oldCancel.eq(award.length-1);
		oldCancel.hide();
		oldCancel.unbind("click");
		newCancel.show();
		newCancel.bind("click", function() {
			$(this).parent().remove();
			showcancel();
			setCount_1();
		});
	}

	function bindAwardEvent() {
		var input = case1.find("input.case1-money"),
			eventSrc = null,
			oldMoney = null;
		focusblur();
		input.bind("focus", function() {
			eventSrc = $(this);
			oldMoney = eventSrc.val();
		});
		input.bind("blur", function() {
			eventSrc.val(eventSrc.val().replace(/[^0-9\.]*|(?:\.$)|(?:^\.)|(?:\s*)/ig,""));
			if(!setCount_1()) eventSrc.val(oldMoney);
		});
	}

	function getChinese(num) {
		var c;
		if(num == 1) c = "一";
		if(num == 2) c = "二";
		if(num == 3) c = "三";
		if(num == 4) c = "四";
		if(num == 5) c = "五";
		if(num == 6) c = "六";
		if(num == 7) c = "七";
		if(num == 8) c = "八";
		if(num == 9) c = "九";
		if(num == 10)c = "十";
		return c;
	}

	function hasAverage(result) {
		var maxLength = String(result).length-1,
			dotIndex = String(result).indexOf("."),
			dotDescSize = maxLength - dotIndex;
		if(dotIndex < 0) return true;
		if(dotDescSize > 2) return false;
		else return true;
	}

	function dealPiece(base) {
		var val, result;
		if(!check_count(m_count_i, m_count_i.val())) {
			at_infoTrace.show("请填写任务赏金", "i");
			clearPiece(); 
			return;
		}
		if(base == "num") {
			val = piecenum.val().replace(/[^0-9]*/g,"");
			if (val == "" || val == "0") { clearPiece(); return }
			else piecenum.val(val);
			result = countm / val;
			if(!hasAverage(result) || result<skillSetting.unitprice) {
				at_infoTrace.show("单个稿件金额须能被赏金总额整除且单价不能低于"+skillSetting.unitprice+"元", "e");
				clearPiece(); 
				return;
			}
			piecepce.val(result);
		} else if (base == "pce") {
			val = piecepce.val().replace(/[^0-9\.]|(?:\.$)|(?:^\.)*/g,"");
			if (val == "" || val == "0") { clearPiece(); return }
			else piecepce.val(val);
			result = countm / val;
			if(!hasAverage(result) || result<skillSetting.unitprice) {
				at_infoTrace.show("单个稿件金额须能被赏金总额整除且单价不能低于"+skillSetting.unitprice+"元", "e");
				clearPiece(); 
				return;
			}
			piecenum.val(result);
		}
		case2_count.text(0);
	}

	function clearPiece() {
		case2_count.text(countm);
		piecenum.val("");
		piecepce.val("");
	}
	submitMoney.click(function() {
		var state = true, errorInfo = "";
		if(m_count_i.val() == "") {
			errorInfo += "任务赏金不能为空";
			state = false;
		}
		var sev = select.val(), count;
		if(sev == 1) {
			if(case1_percentage.text().replace(/[^0-9]/,"") != 0) {
				state = false;
				errorInfo += "选择多人中标时总赏金需要被全部分配" + "<br>";
			}
		} else if (sev == 2) {
			if (skillSetting.selectmode == "default" && e_hideValue.val() == "1") {
			} else {
				if (case2_count.text() != 0) {
					state = false;
					errorInfo += "选择计件模式时总赏金需要被全部分配" + "<br>";
				}
			}
		}
		if (state == false) {
			at_infoTrace.show(errorInfo, "e");
			return false;
		}
		at_loading.show();
		$.ajax({
			type: "POST",
			dataType:"json",
			url: $("#stepForm").attr("action"),
			data:$("#stepForm").serialize(),
			success:function(data, textStatus) {
				at_loading.hide();
				if(data.state == 1){
					eval(data.callback);
				} else if(data.state == -1) {
					at_infoTrace.show(data.msg, "e");		
				} else if(data.state == 0){
					at_infoTrace.show(data.msg, "e");
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrown) {
				at_loading.hide();
				at_infoTrace.show(data.msg, "e");
			}
		});
	});
})();
</script>